﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperKit {
    class NameToDirectory : CommandExecutor {
        public NameToDirectory(ArgReader arg, IExecutorOwner form, string fpath) : base(arg, form, fpath) {

        }

        public override void Execute() {
            base.Execute();
            //Flush("当前处理：{0}", FilePath);
            if (!File.Exists(FilePath)) {
                Error("当前文件不存在：{0}", FilePath);
                End();
                return;
            }

            OnProcess();

            End();
        }

        private void OnProcess() {
            string newName = AdjustName(PureName, ReplacerDict.GalgameReplacer);
            string newDir = Path.Combine(Dir, newName);
            bool isNewExist = Directory.Exists(newDir);

            if (!isNewExist) {
                Directory.CreateDirectory(newDir);
                Flush("成功创建新目录：{0}", newDir);
            } else {
                Notice("创建目标目录已经存在：{0}", newDir);
            }

            string moveFile = Path.Combine(newDir, Name);
            bool isFileExist = File.Exists(moveFile);
            if (isFileExist) {
                Notice("移动目录文件已经存在：{0}", moveFile);
            } else {
                Flush("成功移动文件：{0}", moveFile);
                File.Move(FilePath, moveFile);
            }
        }

    }
}
